/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package models.view;

import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author cepardov
 */
public class Ventas extends javax.swing.JInternalFrame {
    boolean onLogin=true;
    DefaultTableModel modelo= new DefaultTableModel();
    String []datos = new String [5];//Vector String de 5 datos
    /**
     * Creates new form Ventas
     */
    public Ventas() {
        initComponents();
        this.pnlAccion.setVisible(false);
        this.pnlDinamico.setVisible(false);
        this.txtInputCommand.requestFocusInWindow();
        this.bloqTerminal(true);
        this.creaTablaVenta();
        this.tablaVenta.setEnabled(false);
    }
    
    private void bloqTerminal(boolean estado){
        if(estado==true){
            //Bloqueado
            this.txtSecProductoActual(false);
            this.txtSecValoresTotales(false);
            this.avisoLogin();
            this.onLogin=true;
        } else {
            //Desbloqueado
            this.txtSecProductoActual(true);
            this.txtSecValoresTotales(true);
            this.clean();
            this.cleanTotals();
            this.resetDinamico();
            this.resetTabla();
        }
    }
    
    /**
     * Sección de cajas de texto de Producto Actual
     * @param estado <b>true</b> Habilitado, <b>false</b> deshabilitado
     */
    private void txtSecProductoActual(boolean estado){
        this.txtDescripcion.setEnabled(estado);
        this.txtDescuento.setEnabled(estado);
        this.txtCantidad.setEnabled(estado);
        this.txtPrecio.setEnabled(estado);
    }
    
    /**
     * Sección de cajas de texto de totales
     * @param estado <b>true</b> Habilitado, <b>false</b> deshabilitado
     */
    private void txtSecValoresTotales(boolean estado){
        this.txtSubTotal.setEnabled(estado);
        this.txtDescuentoTotal.setEnabled(estado);
        this.txtTotalPagar.setEnabled(estado);
        this.txtFormaPago.setEnabled(estado);
        this.txtVuelto.setEnabled(estado);
    }
    
    private void btnFormaPago(){
        this.pnlAccion.setVisible(true);
        this.txtEfectivo.setText("");
        this.tabs.setSelectedIndex(0);
        this.txtEfectivo.requestFocusInWindow();
    }
    
    /**
     * Sección de Formulario Dinámico.
     */
    
    private void avisoLogin(){
        this.lblFuncionDinamica.setText("Desbloqueo de Terminal");
        this.lblBoxDinamico.setText("Pase su tarjeta de Vendedor por el lector de Cod. de barra");
        this.txtIngresoDinamico.setVisible(false);
        this.pnlDinamico.setVisible(true);
    }
    
    public void login(String cod){
        if("debug".equals(cod)){
            this.onLogin=false;
            this.bloqTerminal(false);
            System.out.println("Estado de desbloqueo="+this.onLogin);
        } else {
            this.txtInputCommand.setText("");
        }
    }
    
    private void btnAnulacion(){
        this.lblFuncionDinamica.setText("Anulación de Producto");
        this.lblBoxDinamico.setText("Cód. Producto a anular");
        this.pnlDinamico.setVisible(true);
        this.txtIngresoDinamico.requestFocusInWindow();
    }
    
    /**
     * Procesa los códigos ingresados a traves del lector de código de barras
     * buscando un producto y lo agrega a la lista correspondiente.
     * @param cod Codigo introducido para realizar la busqueda.
     */
    int sumaVenta = 0;
    int sumaDescuento = 0;
    private void buscaProducto(String cod){
        System.out.println("Result:"+cod);
        
        if("7801620015800".equals(cod)){
            int cantidad=Integer.parseInt(this.txtCantidad.getText());
            int precioUnitario=600;
            
            int precioTotal=precioUnitario*cantidad;
            System.out.println("Precio Total="+precioTotal);
            
            sumaVenta=sumaVenta+precioTotal;
//            sumaDescuento=sumaDescuento;
            
            this.cargaVectorTablaVenta(cod, "Cachantun c/gas 500cc", ""+cantidad, ""+precioUnitario, ""+precioTotal);
            this.agregaProducto();            
            
            this.txtSubTotal.setText(""+sumaVenta);
            
            this.txtInputCommand.setText("");
        } else {
            this.clean();//POSIBLE BUG
        }
    }
    
    private void subTotal(){
        this.txtSubTotal.setText(this.sumaVenta+"");
    }
    
    int total = 0;
    private void total(){
        total=this.sumaVenta-sumaDescuento;
        this.txtTotalPagar.setText(total+"");
    }
    
    private void vuelto(int efectivo){
        int vuelto=efectivo-total;
        this.txtVuelto.setText(vuelto+"");
        this.bloqTerminal(true);
        vuelto=0;
        this.total=0;
        this.sumaDescuento=0;
        this.sumaVenta=0;
        
    }
    
    private void creaTablaVenta(){
        modelo.addColumn("Código");
        modelo.addColumn("Descripción");
        modelo.addColumn("Unidad/Peso");
        modelo.addColumn("Precio Unitario");
        modelo.addColumn("Precio Total");
        this.tablaVenta.setModel(modelo);
    }
    
    /**
     * Agrega nuevos datos de un producto al vector de productos.
     * @param cod Código del producto.
     * @param descripcion Descripcion del producto.
     * @param cantidad Cantidad ya sea en peso o unidad.
     * @param precioUnitario Precio base del producto.
     * @param precioTotal Precio total si es mas de un producto.
     */
    private void cargaVectorTablaVenta(
            String cod, 
            String descripcion, 
            String cantidad, 
            String precioUnitario,
            String precioTotal ){
        //Vector String datos
        datos[0]=cod;
        datos[1]=descripcion;
        datos[2]=cantidad;
        datos[3]=precioUnitario;
        datos[4]=precioTotal;
        this.txtDescripcion.setText(descripcion);
        this.txtCantidad.setText(cantidad);
        this.txtDescuento.setText("0");
        this.txtPrecio.setText(precioTotal);
    }
    
    private void agregaProducto(){
        modelo.addRow(datos);
    }
    
    /**
     * Restablece los valores predeterminados.
     */
    private void clean(){
        this.txtInputCommand.setText("");
        this.txtDescripcion.setText("");
        this.txtDescuento.setText("0");
        this.txtCantidad.setText("1");
        this.txtPrecio.setText("0");
    }
    
    private void cleanTotals(){
        this.txtSubTotal.setText("0");
        this.txtDescuentoTotal.setText("0");
        this.txtTotalPagar.setText("0");
        this.txtFormaPago.setText("0");
        this.txtVuelto.setText("0");
    }
    
    private void resetDinamico(){
        this.pnlDinamico.setVisible(false);
        this.lblFuncionDinamica.setText("");
        this.lblBoxDinamico.setText("");
        this.txtIngresoDinamico.setVisible(true);
    }
    
    private void resetTabla(){
        modelo.getDataVector().removeAllElements();
        revalidate();
    }
    
    private void cierreGaveta(){
        this.clean();
    }
    
    //--Fin Codigo Personalizado--

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaVenta = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        btnFormaPago = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        txtInputCommand = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        txtDescripcion = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        txtDescuento = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        txtCantidad = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        txtPrecio = new javax.swing.JTextField();
        jPanel11 = new javax.swing.JPanel();
        txtSubTotal = new javax.swing.JTextField();
        jPanel12 = new javax.swing.JPanel();
        txtDescuentoTotal = new javax.swing.JTextField();
        jPanel13 = new javax.swing.JPanel();
        txtTotalPagar = new javax.swing.JTextField();
        jPanel14 = new javax.swing.JPanel();
        txtVuelto = new javax.swing.JTextField();
        jPanel15 = new javax.swing.JPanel();
        txtFormaPago = new javax.swing.JTextField();
        pnlAccion = new javax.swing.JPanel();
        tabs = new javax.swing.JTabbedPane();
        tabEfectivo = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtEfectivo = new javax.swing.JTextField();
        tabCredito = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txtMaternoCliente = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtPaternoCliente = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtRutCliente = new javax.swing.JTextField();
        txtNombreCliente = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel16 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        pnlDinamico = new javax.swing.JPanel();
        lblFuncionDinamica = new javax.swing.JLabel();
        lblBoxDinamico = new javax.swing.JLabel();
        txtIngresoDinamico = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Sección Detalle", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        tablaVenta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tablaVenta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaVentaMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tablaVenta);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Funciones"));

        jButton2.setText("Sub-Total [F1]");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        btnFormaPago.setText("Forma Pago [F5]");
        btnFormaPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFormaPagoActionPerformed(evt);
            }
        });

        jButton3.setText("Total [F2]");

        jButton4.setText("Anulación [F4]");

        jButton5.setText("Desc. Manual [F3]");

        jButton6.setText("Mostrar Escritorio [F12]");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnFormaPago, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnFormaPago)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel1.setText("Barra de estado inactiva");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Producto Actual"));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Código de Barra"));

        txtInputCommand.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        txtInputCommand.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtInputCommandKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtInputCommandKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtInputCommand, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtInputCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Descripción"));

        txtDescripcion.setEditable(false);
        txtDescripcion.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        txtDescripcion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDescripcionFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Desc. (%)"));

        txtDescuento.setEditable(false);
        txtDescuento.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        txtDescuento.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtDescuento.setText("0");
        txtDescuento.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDescuentoFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtDescuento, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Cantidad"));

        txtCantidad.setEditable(false);
        txtCantidad.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        txtCantidad.setForeground(new java.awt.Color(0, 84, 255));
        txtCantidad.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCantidad.setText("1");
        txtCantidad.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCantidadFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtCantidad, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Precio"));

        txtPrecio.setEditable(false);
        txtPrecio.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        txtPrecio.setForeground(new java.awt.Color(2, 171, 5));
        txtPrecio.setText("0");
        txtPrecio.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtPrecioFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtPrecio, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 9, Short.MAX_VALUE))
        );

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Sub-Total", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14), new java.awt.Color(255, 65, 0))); // NOI18N

        txtSubTotal.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        txtSubTotal.setForeground(new java.awt.Color(16, 0, 255));
        txtSubTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtSubTotal.setText("0");
        txtSubTotal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtSubTotalFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtSubTotal)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(txtSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total Desc.", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14), new java.awt.Color(1, 115, 83))); // NOI18N

        txtDescuentoTotal.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        txtDescuentoTotal.setForeground(new java.awt.Color(2, 66, 139));
        txtDescuentoTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDescuentoTotal.setText("0");
        txtDescuentoTotal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDescuentoTotalFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtDescuentoTotal)
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addComponent(txtDescuentoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 8, Short.MAX_VALUE))
        );

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total a Pagar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14), new java.awt.Color(1, 152, 8))); // NOI18N

        txtTotalPagar.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        txtTotalPagar.setForeground(new java.awt.Color(40, 163, 43));
        txtTotalPagar.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTotalPagar.setText("0");
        txtTotalPagar.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtTotalPagarFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtTotalPagar, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addComponent(txtTotalPagar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 14, Short.MAX_VALUE))
        );

        jPanel14.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Vuelto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N

        txtVuelto.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        txtVuelto.setForeground(new java.awt.Color(255, 0, 13));
        txtVuelto.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtVuelto.setText("0");
        txtVuelto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtVueltoFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtVuelto)
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addComponent(txtVuelto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 14, Short.MAX_VALUE))
        );

        jPanel15.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ingreso Dinero", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N

        txtFormaPago.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        txtFormaPago.setForeground(new java.awt.Color(255, 100, 0));
        txtFormaPago.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtFormaPago.setText("0");
        txtFormaPago.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtFormaPagoFocusGained(evt);
            }
        });

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtFormaPago)
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addComponent(txtFormaPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 14, Short.MAX_VALUE))
        );

        pnlAccion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Forma de Pago", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14))); // NOI18N

        tabs.setTabPlacement(javax.swing.JTabbedPane.LEFT);

        jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        jLabel3.setText("Efectivo $");

        txtEfectivo.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        txtEfectivo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtEfectivoKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout tabEfectivoLayout = new javax.swing.GroupLayout(tabEfectivo);
        tabEfectivo.setLayout(tabEfectivoLayout);
        tabEfectivoLayout.setHorizontalGroup(
            tabEfectivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabEfectivoLayout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtEfectivo, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(223, Short.MAX_VALUE))
        );
        tabEfectivoLayout.setVerticalGroup(
            tabEfectivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabEfectivoLayout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(tabEfectivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtEfectivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(191, Short.MAX_VALUE))
        );

        tabs.addTab("Efectivo [F1]", tabEfectivo);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del  Cliente"));

        jLabel6.setText("Apellido Materno");

        jLabel5.setText("Apellido Paterno");

        jLabel2.setText("RUT ");

        txtRutCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtRutClienteKeyPressed(evt);
            }
        });

        jLabel4.setText("Nombre");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPaternoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(txtMaternoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(9, 9, 9)
                        .addComponent(txtRutCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(115, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtRutCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPaternoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMaternoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel16.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la cuenta"));

        jLabel7.setText("Cupo Total");

        jLabel8.setText("Cupo Disponible");

        jLabel9.setText("Fecha de Pago");

        jLabel10.setText("Estado de la cuenta");

        jLabel11.setText("Observaciones");

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField5)
                    .addGroup(jPanel16Layout.createSequentialGroup()
                        .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel16Layout.createSequentialGroup()
                                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel11))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout tabCreditoLayout = new javax.swing.GroupLayout(tabCredito);
        tabCredito.setLayout(tabCreditoLayout);
        tabCreditoLayout.setHorizontalGroup(
            tabCreditoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabCreditoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabCreditoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tabCreditoLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(128, 128, 128))
                    .addGroup(tabCreditoLayout.createSequentialGroup()
                        .addComponent(jPanel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        tabCreditoLayout.setVerticalGroup(
            tabCreditoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabCreditoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabs.addTab("Crédito [F2]", tabCredito);

        javax.swing.GroupLayout pnlAccionLayout = new javax.swing.GroupLayout(pnlAccion);
        pnlAccion.setLayout(pnlAccionLayout);
        pnlAccionLayout.setHorizontalGroup(
            pnlAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAccionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tabs))
        );
        pnlAccionLayout.setVerticalGroup(
            pnlAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAccionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tabs)
                .addContainerGap())
        );

        pnlDinamico.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Funciones Dinámicas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        lblFuncionDinamica.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        lblFuncionDinamica.setText("Descripción de la función");

        lblBoxDinamico.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        lblBoxDinamico.setText("Caja de Texto");

        txtIngresoDinamico.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        txtIngresoDinamico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtIngresoDinamicoKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout pnlDinamicoLayout = new javax.swing.GroupLayout(pnlDinamico);
        pnlDinamico.setLayout(pnlDinamicoLayout);
        pnlDinamicoLayout.setHorizontalGroup(
            pnlDinamicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDinamicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDinamicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFuncionDinamica)
                    .addGroup(pnlDinamicoLayout.createSequentialGroup()
                        .addComponent(lblBoxDinamico)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtIngresoDinamico, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlDinamicoLayout.setVerticalGroup(
            pnlDinamicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDinamicoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFuncionDinamica)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDinamicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBoxDinamico)
                    .addComponent(txtIngresoDinamico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(pnlAccion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(pnlDinamico, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel15, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(25, 25, 25))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlDinamico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlAccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Double SubTotal=Double.parseDouble(this.txtSubTotal.getText());
        Double TotalDescuento=Double.parseDouble(this.txtDescuentoTotal.getText());
//        Double Total=Double.parseDouble(this.txtTP.getText());
        //Parcial
        Double IngresoPago=Double.parseDouble(this.txtFormaPago.getText());
//        Double Vuelto=Double.parseDouble(this.txtVuelto.getText());
        
        //Calculo
        Double Total=SubTotal-TotalDescuento;
        this.txtTotalPagar.setText(Total.toString());
        
        //Calculo Vuelto
        Double Vuelto=IngresoPago-Total;
        this.txtVuelto.setText(Vuelto.toString());
    }//GEN-LAST:event_jButton2ActionPerformed

    private void txtEfectivoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEfectivoKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            // Enter was pressed. Your code goes here.
            int efectivo=Integer.parseInt(this.txtEfectivo.getText());
            this.vuelto(efectivo);
            this.txtFormaPago.setText(efectivo+"");
            this.txtInputCommand.requestFocusInWindow();
            this.pnlAccion.setVisible(false);
        }
        if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            // Enter was pressed. Your code goes here.
            this.pnlAccion.setVisible(false);
        }
        if(evt.getKeyCode() == KeyEvent.VK_F2) {
            // Enter was pressed. Your code goes here.
            this.tabs.setSelectedIndex(1);
        }
    }//GEN-LAST:event_txtEfectivoKeyPressed

    private void txtInputCommandKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtInputCommandKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            // Enter was pressed. Your code goes here.
            String cod=this.txtInputCommand.getText();
            if(this.onLogin==true){
                this.login(cod);
                System.out.println("[i] Proceso de desbloq.");
            } else {
                this.buscaProducto(cod);
                System.out.println("[i] Ejecutando venta");
            }
        }
        if(evt.getKeyCode() == KeyEvent.VK_INSERT) {
            // Enter was pressed. Your code goes here.
            String num=this.txtInputCommand.getText();
            this.txtCantidad.setText(num);
            this.txtInputCommand.setText("");
        }
        if(evt.getKeyCode() == KeyEvent.VK_F1) {
            // Enter was pressed. Your code goes here.
            this.subTotal();
        }
         if(evt.getKeyCode() == KeyEvent.VK_F2) {
            // Enter was pressed. Your code goes here.
            this.total();
        }
        if(evt.getKeyCode() == KeyEvent.VK_F4) {
            // Enter was pressed. Your code goes here.
            this.btnAnulacion();
        }
        if(evt.getKeyCode() == KeyEvent.VK_F5) {
            // Enter was pressed. Your code goes here.
            this.btnFormaPago();
        }
        if(evt.getKeyCode() == KeyEvent.VK_F12) {
            // Enter was pressed. Your code goes here.
            this.setVisible(false);
            JOptionPane.showMessageDialog(null,"Estimado Usuario:\n"
                    + "Una venta en curso ha sido minimizada para retornar presione tecla F1,"
                    + " si desea utilizar otra función presione la tecla que se indica en menu principal"
                    + " o utilizando el puntero del mouse.\n"
                    + "para retomar los atajos del teclado haga clic en la zona azul.", "Uso de teclado", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_txtInputCommandKeyPressed

    private void btnFormaPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormaPagoActionPerformed
        // TODO add your handling code here:
        this.btnFormaPago();
    }//GEN-LAST:event_btnFormaPagoActionPerformed

    private void txtDescripcionFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescripcionFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
        
    }//GEN-LAST:event_txtDescripcionFocusGained

    private void txtDescuentoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescuentoFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtDescuentoFocusGained

    private void txtCantidadFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCantidadFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtCantidadFocusGained

    private void txtPrecioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecioFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtPrecioFocusGained

    private void txtInputCommandKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtInputCommandKeyReleased
        // TODO add your handling code here:
        
    }//GEN-LAST:event_txtInputCommandKeyReleased

    private void txtRutClienteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRutClienteKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            // Enter was pressed. Your code goes here.

        }
        if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            // Enter was pressed. Your code goes here.
            this.txtInputCommand.requestFocusInWindow();
            this.pnlAccion.setVisible(false);
        }
        if(evt.getKeyCode() == KeyEvent.VK_F1) {
            // Enter was pressed. Your code goes here.
            this.tabs.setSelectedIndex(0);
        }
    }//GEN-LAST:event_txtRutClienteKeyPressed

    private void txtIngresoDinamicoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIngresoDinamicoKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
            // Enter was pressed. Your code goes here.

        }
        if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            // Enter was pressed. Your code goes here.
            this.txtInputCommand.requestFocusInWindow();
            this.pnlDinamico.setVisible(false);
            this.txtIngresoDinamico.setText("");
        }
    }//GEN-LAST:event_txtIngresoDinamicoKeyPressed

    private void txtSubTotalFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSubTotalFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtSubTotalFocusGained

    private void txtDescuentoTotalFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescuentoTotalFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtDescuentoTotalFocusGained

    private void txtTotalPagarFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTotalPagarFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtTotalPagarFocusGained

    private void txtFormaPagoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtFormaPagoFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtFormaPagoFocusGained

    private void txtVueltoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtVueltoFocusGained
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_txtVueltoFocusGained

    private void tablaVentaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaVentaMouseClicked
        // TODO add your handling code here:
        this.txtInputCommand.requestFocusInWindow();
    }//GEN-LAST:event_tablaVentaMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnFormaPago;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JLabel lblBoxDinamico;
    private javax.swing.JLabel lblFuncionDinamica;
    private javax.swing.JPanel pnlAccion;
    private javax.swing.JPanel pnlDinamico;
    private javax.swing.JPanel tabCredito;
    private javax.swing.JPanel tabEfectivo;
    private javax.swing.JTable tablaVenta;
    private javax.swing.JTabbedPane tabs;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtDescuento;
    private javax.swing.JTextField txtDescuentoTotal;
    private javax.swing.JTextField txtEfectivo;
    private javax.swing.JTextField txtFormaPago;
    private javax.swing.JTextField txtIngresoDinamico;
    public javax.swing.JTextField txtInputCommand;
    private javax.swing.JTextField txtMaternoCliente;
    private javax.swing.JTextField txtNombreCliente;
    private javax.swing.JTextField txtPaternoCliente;
    private javax.swing.JTextField txtPrecio;
    private javax.swing.JTextField txtRutCliente;
    private javax.swing.JTextField txtSubTotal;
    private javax.swing.JTextField txtTotalPagar;
    private javax.swing.JTextField txtVuelto;
    // End of variables declaration//GEN-END:variables
}
